package cn.wolfcode.wms.util;



import lombok.Getter;
import lombok.Setter;

import java.util.Collections;
import java.util.List;

@Getter
public class PageResult {
    public static final PageResult EMPTY_RESULT = new PageResult(1,1,0, Collections.emptyList());
    private  int currentPage;
    private int  pageSize;

    private int rows;
    private List<?> data;

    private int endPage;
    private int prevPage;
    private int nextPage;

    public PageResult(int currentPage, int pageSize, int rows, List<?> data) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.rows = rows;
        this.data = data;
        if (rows<= pageSize) {
            endPage =1;
            nextPage=1;
            prevPage =1;
            return;
        }
        endPage = rows % pageSize == 0 ? rows / pageSize : rows / pageSize +1;
        prevPage = currentPage > 1 ? currentPage -1 : 1;
        nextPage = currentPage <endPage ? currentPage +1 : endPage;
    }
}
